package com.wangzha.api;

import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.wangzha.common.response.R;
import org.apache.commons.lang3.StringUtils;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

@Path("/download")
public class DownloadController extends Controller {

    public void script() {
        String fileName = getPara("name");
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("script/" + fileName);
        InputStream input = new BufferedInputStream(inputStream);
        // 设置输出的格式
        getResponse().reset();
        //getResponse().setContentType("bin");
        byte[] b = new byte[1024];
        int len;
        try {
            OutputStream out = getResponse().getOutputStream();
            while ((len = input.read(b)) > 0) {
                out.write(b, 0, len);
            }
            out.close();
            input.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        renderNull();
    }

}
